package com.jiaai.cloud.live.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.page.FrontPage;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.jiaai.cloud.live.entity.TLiveSystemSetting;
import com.jiaai.cloud.live.service.ITLiveSystemSettingService;
import com.jiaai.cloud.system.entity.TRole;
import com.jiaai.cloud.user.service.ITUserLevelSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-09-02
 */
@Controller
@RequestMapping("/api/manage/tLiveSystemSetting")
public class TLiveSystemSettingController {
	@Autowired
    private ITLiveSystemSettingService itLiveSystemSettingService;

    //可以根据Id查找,不传id查所有
    @RequestMapping(value = "/findByAll", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object findByAll(FrontPage page) throws ServiceException {
            try {
                EntityWrapper wrapper = new EntityWrapper();
                return RestResultGenerator.genSuccessResult(itLiveSystemSettingService.selectPage(page.getPagePlus(), wrapper));
            } catch (Exception e) {
                throw new ServiceException("查询失敗", e.getMessage());
            }
        }
    // 通过anchorId删除
    @RequestMapping(value = "/deleteId/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("id")  Integer id) throws ServiceException {
        try {
            itLiveSystemSettingService.deleteById(id);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }
    //通过Id查找所有
    @RequestMapping(value ="/findById/{id}",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object findById(@PathVariable("id") Integer id ) throws ServiceException {
        try {
            return RestResultGenerator.genSuccessResult( itLiveSystemSettingService.selectById(id));
        } catch (Exception e) {
            throw new ServiceException("查询失败", e.getMessage());
        }
    }

    //可以添加，有的话可以修改
    @RequestMapping( value ="/edit" ,method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"})
    public  Object edit(@RequestBody TLiveSystemSetting liveSystemSetting) throws ServiceException{
        try {
            itLiveSystemSettingService.insertOrUpdate(liveSystemSetting);
            return null;
        } catch (Exception e) {
            throw new ServiceException("更改失敗", e.getMessage());
        }
    }




}
